package com.jic.order.impl;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.Page;

import com.jic.order.entity.OrderExamine;
import com.jic.order.manage.request.OrderExamineRequest;
import com.jic.order.mapper.OrderExamineMapper;
import com.jic.order.service.OrderExamineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 订单审核设置
 *
 * @author :
 * @version : v1.0.0
 * @email :
 * @since : 2020-05-06 10:37:31
 */
@Service
public class OrderExamineServiceImpl implements OrderExamineService {

    @Autowired
    private OrderExamineMapper orderExamineMapper;

    @Override
    public long editOrderExamine(OrderExamine orderExamine) {
        if (orderExamine.getId() == null) {
            long flag = orderExamineMapper.insert(orderExamine);
            return flag;
        } else {
            long flag = orderExamineMapper.update(orderExamine);
            return flag;
        }
    }

    @Override
    public long delete(Long id) {
        return orderExamineMapper.delete(id);
    }

    @Override
    public long update(OrderExamine orderExamine) {
        return orderExamineMapper.update(orderExamine);
    }

    @Override
    public OrderExamine queryByPrimaryKey(Long id) {
        return orderExamineMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<OrderExamine> query(OrderExamine orderExamine) {
        return orderExamineMapper.query(orderExamine);
    }

    @Override
    public PageResult<OrderExamine> queryPage(OrderExamine orderExamine, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<OrderExamine> list = orderExamineMapper.queryPage(startIndex, pageQuery.getLimit(), orderExamine);
        long count = orderExamineMapper.queryPageCount(orderExamine);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public Boolean batchStatusOrderExamine(OrderExamineRequest request) {
        orderExamineMapper.batchUpdateStatus(request);
        return true;
    }
}